﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace AjaxLibrary
{
    class recipe : IHttpHandler,IRequiresSessionState
    {
        bool IHttpHandler.IsReusable
        {
            get { return true; }
        }

        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            string param = context.Request.QueryString["Param"];
            switch (param)
            {
                case "isExistsRecipeName":
                    isExistsRecipeName(context.Request,context.Response);
                    break;
                default:
                    context.Response.Output.Write("Unknow request URL");
                    break;
            }
        }

        private void isExistsRecipeName(HttpRequest request, HttpResponse response)
        {
            int companyId = logic.customer.getCompanyId();
            if (!string.IsNullOrEmpty(request.QueryString["name"]) && companyId != 0)
            {
                if (logic.recipe.isExistsRecipeName(companyId, request.QueryString["name"],"2"))
                {
                    response.Write("1");
                }
                else
                {
                    response.Write("0");
                }
            }
            else
            {
                response.Write("0");
            }
        }
    }
}
